package com.grf.hadoop.word_count;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;

import java.io.IOException;

public class MyDriver  {

    public static void main(String[]args) throws IOException, ClassNotFoundException, InterruptedException {
        Configuration configuration = new Configuration();
        //获取Job对象
        Job job = Job.getInstance(configuration);
        //设置Jar包存储位置
        job.setJarByClass(MyDriver.class);
        //关联Mapper和Reduce类
        job.setMapperClass(MyMapper.class);
        job.setReducerClass(MyReducer.class);
        //设置Mapper阶段输出的key和value类型
        job.setMapOutputKeyClass(Text.class);
        job.setMapOutputValueClass(IntWritable.class);
        //设置最终输出的key和value类型
        job.setOutputKeyClass(Text.class);
        job.setOutputValueClass(IntWritable.class);
        //设置Combiner
        job.setCombinerClass(WordCountCombiner.class);
        //设置输入输出路径
        FileInputFormat.setInputPaths(job,new Path("C:\\Users\\Administrator\\Desktop\\phone.txt"));
        FileOutputFormat.setOutputPath(job,new Path("C:\\Users\\Administrator\\Desktop\\output"));
        //提交Job
        boolean res = job.waitForCompletion(true);

    }
}
